/**
 * 
 */
package br.com.framework.app.model;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.Size;

import br.com.framework.persistencia.model.AuditedEntity;

/**
 * @author Cleber
 *
 */
@Entity
@Table(name = "USUARIO")
public class Usuario extends AuditedEntity {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String nome;
	private String login;
	private String senha;
	
	private Set<Papel> papeis;
	
	/**
	 * 
	 */
	public Usuario() {
	}
	
	@Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="SEQ_USUARIO")
	@SequenceGenerator(name="SEQ_USUARIO", sequenceName="SEQ_USUARIO", allocationSize=1, initialValue=0)
	@Column(name = "ID_USUARIO")
	public Long getId() {
		return super.getId();
	}
	
	@Column(name = "NOME", length = 255, nullable = false)
	@Size(min = 1, max = 255, message = "{usuario.nome.tamanhoInvalido}")
	public String getNome() {
		return nome;
	}
	
	public void setNome(String nome) {
		this.nome = nome;
	}
	
	/**
	 * @return the login
	 */
	@Column(name = "LOGIN", length = 30, nullable = false)
	@Size(min = 1, max = 30, message = "{usuario.login.tamanhoInvalido}")
	public String getLogin() {
		return login;
	}

	/**
	 * @param login the login to set
	 */
	public void setLogin(String login) {
		this.login = login;
	}

	/**
	 * @return the senha
	 */
	@Column(name = "SENHA", length = 255, nullable = false)
	@Size(min = 3, max = 255, message = "{usuario.senha.tamanhoInvalido}")
	public String getSenha() {
		return senha;
	}

	/**
	 * @param senha the senha to set
	 */
	public void setSenha(String senha) {
		this.senha = senha;
	}

	
	@ManyToMany(targetEntity=Papel.class)
	@JoinTable(name = "USUARIO_PAPEL", 
		joinColumns = @JoinColumn(name = "ID_USUARIO", referencedColumnName = "ID_USUARIO"), 
		inverseJoinColumns = @JoinColumn(name = "ID_PAPEL", referencedColumnName = "ID_PAPEL"))
	public Set<Papel> getPapeis() {
		return papeis;
	}
	
	public void setPapeis(Set<Papel> papeis) {
		this.papeis = papeis;
	}
}
